package com.dkd.manage.controller;

import com.dkd.common.core.domain.R;
import com.dkd.manage.pojo.dto.EmpQueryListDto;
import com.dkd.manage.pojo.entity.Emp;
import com.dkd.manage.result.PageResult;
import com.dkd.manage.service.EmpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "人员管理相关接口")
@RequestMapping("/manage/emp")
public class EmpController {

    @Autowired
    private EmpService empService;

    @ApiOperation("分页查询人员列表")
    @PreAuthorize("@ss.hasPermi('manage:emp:list')")
    @GetMapping("/list")
    public R<PageResult<Emp>> list(EmpQueryListDto empQueryListDto) {
        log.info("分页查询人员列表：{}", empQueryListDto);
        PageResult<Emp> result = empService.list(empQueryListDto);
        return R.ok(result);
    }

    @ApiOperation("新增人员")
    @PreAuthorize("@ss.hasPermi('manage:emp:add')")
    @PostMapping
    public R<Integer> add(@RequestBody Emp emp) {
        log.info("新增人员：{}", emp);
        Integer rows = empService.add(emp);
        return R.ok(rows);
    }

    @ApiOperation("根据id查询人员")
    @PreAuthorize("@ss.hasPermi('manage:emp:query')")
    @GetMapping("/{id}")
    public R<Emp> getEmpById(@PathVariable Long id) {
        log.info("根据id查询人员：{}", id);
        Emp emp = empService.getEmpById(id);
        return R.ok(emp);
    }

    @ApiOperation("修改人员")
    @PreAuthorize("@ss.hasPermi('manage:Emp:edit')")
    @PutMapping
    public R<Integer> edit(@RequestBody Emp emp) {
        log.info("修改人员：{}", emp);
        Integer rows = empService.edit(emp);
        return R.ok(rows);
    }

    @ApiOperation("根据id删除人员")
    @PreAuthorize("@ss.hasPermi('manage:emp:remove')")
    @DeleteMapping("/{ids}")
    public R<Integer> deleteEmpById(@PathVariable Long[] ids) {
        log.info("根据id删除区域：{}", ids);
        Integer rows = empService.deleteEmpById(ids);
        return R.ok(rows);
    }

}
